#ifndef __MY_PROTOCAL_H__
#define __MY_PROTOCAL_H__
#include "Util.hpp"
#include "Database.hpp"

class Response
{
public:
    // 落子请求的响应
    static Json::Value ChessSuccess(const Json::Value &req)
    {
        // 请求中的信息都保留，包括操作类型"chess"，下棋位置，用户id等
        Json::Value resq = req;
        return resq;
    }

    // 游戏结束的响应
    static Json::Value GameOver(id_t winner, const std::string &result)
    {
        Json::Value resq;
        resq["op_type"] = "game_over";
        resq["winner"] = winner;
        resq["result"] = result;
        return resq;
    }

    // 聊天消息响应
    static Json::Value ChatSuccess(const Json::Value &req)
    {
        // 包含op_type，uid，message
        Json::Value resq = req;
        return resq;
    }
    
    // 一般WebSocket请求的响应消息
    static Json::Value WebSocket(const std::string &op_type, const std::string &result)
    {
        Json::Value resq;
        resq["op_type"] = op_type;
        resq["result"] = result;
        return resq;
    }
    
    // 房间准备好的消息
    static Json::Value RoomReady(id_t uid, id_t room_id, id_t white_id, id_t black_id, Table_User* tb)
    {
        Json::Value resq;
        resq["op_type"] = "room_ready";
        resq["room_id"] = room_id;
        resq["uid"] = uid;
        resq["white_id"] = white_id;
        resq["black_id"] = black_id;
        Json::Value tmp;
        tb->SelectById(white_id, tmp);
        resq["white_name"] = tmp["name"];
        resq["white_points"] = tmp["points"];
        tb->SelectById(black_id, tmp);
        resq["black_name"] = tmp["name"];
        resq["black_points"] = tmp["points"];
        return resq;
    }

    // 匹配成功的消息
    static Json::Value MatchSuccess()
    {
        Json::Value resq;
        resq["op_type"] = "match_success";
        return resq;
    }
};

#endif